package net.siufung.boot.knife4j.autoconfigure;

import cn.hutool.core.util.StrUtil;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.siufung.boot.knife4j.properties.Knife4jProperties;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Knife4jAutoConfig
 * @author SIUFUNG
 */
@Slf4j
@Configuration
@EnableSwagger2
@EnableKnife4j
@EnableConfigurationProperties({Knife4jProperties.class})
@AllArgsConstructor
public class Knife4jAutoConfig {

    private final Knife4jProperties knife4jProperties;

    /**
     * API 页面展示信息
     */
    @Bean(name = "apiInfo")
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(knife4jProperties.getTitle())
                .description(knife4jProperties.getDescription())
                .termsOfServiceUrl(knife4jProperties.getTermsOfServiceUrl())
                .contact(new Contact(knife4jProperties.getContact(), knife4jProperties.getTermsOfServiceUrl(), knife4jProperties.getEmail()))
                .version(StrUtil.concat(false,
                        "Application Version: ",
                        knife4jProperties.getVersion(),
                        ", Spring Boot Version: ",
                        SpringBootVersion.getVersion()))
                .build();
    }



}
